var radioOptionCount = 2;
var checkOptionCount = 3;
var radioCount = 0;
var textCount = 0;
var checkCount = 0;
var allCount = 0;
var radio = new Array();for(var k=0;k<=10;k++){radio[k]=new Array()};
var text = new Array();
var check = new Array();for(var j=0;j<=10;j++){check[j]=new Array()};
var timu = new Array();
var num = new Array();
var arr = [];
var userId = "";

function getUserinfo(){
	$.get("", function(data){
		userId = data;
		arr[0] = userId; 
	});
}

function addRadioOption(){
	radioOptionCount++;
	if (radioOptionCount<=4) {
	$("#radioOption").append("<div class='form-group'><label for='radioOption" + radioOptionCount 
		+ "' class='col-sm-3 control-label'>选项" + radioOptionCount 
		+ "：</label><div class='col-sm-8'><input type='text' id='radioOption" + radioOptionCount 
		+ "' name='radioOption" + radioOptionCount
		+"' class='form-control well' placeholder='输入选项" + radioOptionCount + "' /></div</div>");
}else{
	alert("最多设置4个选项！")
	}
}

function addRadio(){
	radioCount++;
	allCount = radioCount + textCount + checkCount;
	if(allCount<=10){
		radio[radioCount][0] = allCount;
		radio[radioCount][5] = $("#radioTitle").val();
		$("#registration").append("<h2>"+allCount+".</h2><h4>"+radio[radioCount][5]+"</h4>");
			for (var i = 1; i <= radioOptionCount; i++) {
				radio[radioCount][i] = $("#radioOption"+i).val();
				var str = String.fromCharCode(i+64);
				$("#registration").append("<div class='form-group'><label for='radioUserOption"+ radioCount + i 
					+ "' class='col-sm-3 control-label'>" + str 
					+ ":&nbsp;&nbsp;&nbsp;&nbsp;" + radio[radioCount][i]
					+"</label><input type='radio' name='radioUserOption' id='radioUserOption"+ radioCount +i 
					+ "'value='"+ radio[radioCount][i] +"'/></div>");
				timu.push(radio[radioCount][i])
				arr[allCount]={ 
					num : allCount, 
					title : $("#radioTitle").val(),
					desc : timu, 
					type : "radio",
				};
			}
			timu = [];
	}else{
		alert("题目超出上限！")
	}		
}

function addTextQuestion(){
	textCount++;
	allCount = radioCount + textCount + checkCount;
	if(allCount<=10){
		text[textCount] = $("#textTitle").val();
		$("#registration").append("<h2>"+allCount+".</h2><h4>"+text[textCount]+"</h4>");
				$("#registration").append("<div class='form-group'><label for='textAnswer"+ textCount
					+ "' class='col-sm-3 control-label'>"
					+ "&nbsp;&nbsp;&nbsp;&nbsp;</label><input type='text' name='textAnswer' id='textAnswer"+ textCount
					+ "' class='form-control well'/></div>");
				timu.push(text[textCount])
				arr[allCount]={ 
					num : allCount, 
					title : $("#textTitle").val(),
					desc : timu, 
					type : "text",
				}
				timu = [];
	}else{
		alert("题目超出上限！")
	}
}

function addCheckOption(){
	checkOptionCount++;
	if(checkOptionCount<=4){
	$("#checkOption").append("<div class='form-group'><label for='checkOption" + checkOptionCount 
		+ "' class='col-sm-3 control-label'>选项" + checkOptionCount 
		+ "：</label><div class='col-sm-8'><input type='text' id='checkOption" + checkOptionCount 
		+ "' name='checkOption" + checkOptionCount
		+"' class='form-control well' placeholder='输入选项" + checkOptionCount + "' /></div</div>");
	}else{
		alert("最多设置4个选项！")
	}
}

function addCheck(){
	checkCount++;
	allCount = radioCount + textCount + checkCount;
	if(allCount<=10){
		check[checkCount][0] = $("#checkTitle").val();
		$("#registration").append("<h2>"+allCount+".</h2><h4>"+check[checkCount][0]+"</h4>");
			for (var i = 1; i <= checkOptionCount; i++) {
				check[checkCount][i] = $("#checkOption"+i).val();
				var str = String.fromCharCode(i+64);
				$("#registration").append("<div class='form-group'><label for='checkUserOption"+ checkCount + i 
					+ "' class='col-sm-3 control-label'>" + str 
					+ ":&nbsp;&nbsp;&nbsp;&nbsp;" + check[checkCount][i]
					+"</label><input type='checkbox' name='checkUserOption' id='checkUserOption"+ checkCount +i 
					+ "'value='"+ check[checkCount][i] +"'/></div>");
				timu.push(check[checkCount][i])
				arr[allCount]={ 
					num : allCount, 
					title : $("#checkTitle").val(),
					desc : timu, 
					type : "check",
				}
			}
			timu = [];
	}else{
		alert("题目超出上限！")
	}		
}


function upload(){
	$("#arr").val(JSON.stringify(arr));
	return true;
}  
